﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Moe_v0._1
{
    class SubSentence
    {
        private KeyValuePair<Phrase, char> _subSentence;
        private string _originalInput = "";
        private char[] punctuations = EnSegmentor.PunctuationsString.ToCharArray();
        public SubSentence(string input)
        {
            _originalInput = input;

            // Remove extra punctuations at the beginning of the input string.
            string tempString = input.TrimStart(punctuations);

            if (tempString.Length > 0)
            {
                // Not an empty subsentence with punctuations only.
                var ret = tempString.Split(punctuations);
                if (ret.Count() > 0)
                {
                    char punctuation = '.';
                    if (tempString.Length > ret[0].Length)
                    {
                        punctuation = tempString[ret[0].Length];
                    }
                    _subSentence = new KeyValuePair<Phrase,char>(new Phrase(ret[0]), punctuation);
                    if (MoeDebugger.IsDebugging)
                    {
                        MoeDebugger.AddDebugInfo(
                            "SubSentence: <phrase> [" + ret[0] + "], <punctuation> [" + punctuation.ToString() + "]");
                    }
                }
            }
            else
            {
                // An empty subsentence with punctuations only.
                _subSentence = new KeyValuePair<Phrase, char>(new Phrase(""), '\0');
                if (MoeDebugger.IsDebugging)
                {
                    MoeDebugger.AddDebugInfo("SubSentence: [" + _originalInput + "] is NOT legal sub sentence.");
                }
            }
        }

        public Phrase PhrasePart
        {
            get
            {
                Debug.Assert(_subSentence.Key != null);
                return _subSentence.Key;
            }
        }
        public char Punctuation
        {
            get
            {
                return _subSentence.Value;
            }
        }
    }
}
